
import copy

import ioelement
import ioml

class Monitor:
    
    def __init__(self,env,path):
        self.env = env
        self.path = path
    
    def __str__(self):
        return self.string

class Get(Monitor):
    
    def __init__(self,env,path):
        Monitor.__init__(self,env,path)
        
        header = ioelement.IOElement('Monitor',{'type':'Get','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header))
    
class Add(Monitor):
    
    def __init__(self,env,path,newioelement):
        Monitor.__init__(self,env,path)
        
        header = ioelement.IOElement('Monitor',{'type':'Add','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header,bodyelement=copy.deepcopy(newioelement)))

class Delete(Monitor):
    
    def __init__(self,env,path,key):
        Monitor.__init__(self,env,path)
        self.key = key
        
        header = ioelement.IOElement('Monitor',{'type':'Delete','path':self.path,'key':key})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header))
     
class Subscribe(Monitor):
    
    def __init__(self,env,path,subscriber, anchor=False):
        Monitor.__init__(self,env,path)
        
        header = ioelement.IOElement('Monitor',{'type':'Subscribe','path':self.path,'anchor':str(anchor)})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header,bodyelement=subscriber._to_element()))
     
class Unsubscribe(Monitor):
    
    def __init__(self,env,path,subscriberkey, anchor=False):
        Monitor.__init__(self,env,path)
        
        header = ioelement.IOElement('Monitor',{'type':'Unsubscribe','path':self.path,'key':str(subscriberkey),'anchor':str(anchor)})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header))

class AddAccess(Monitor):
    
    def __init__(self,env,path,accesselement):
        Monitor.__init__(self,env,path)
        
        header = ioelement.IOElement('Monitor',{'type':'AddAccess','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header,bodyelement=copy.deepcopy(accesselement)))
        
class RemoveAccess(Monitor):
    
    def __init__(self,env,path,accesskey):
        Monitor.__init__(self, env, path)
        
        header = ioelement.IOElement('Monitor',{'type':'RemoveAccess','path':self.path,'key':accesskey})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header))
        
class AddExtension(Monitor):
    
    def __init__(self,env,path,extension):
        Monitor.__init__(self, env, path)
        
        header = ioelement.IOElement('Monitor',{'type':'AddExtension','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header,bodyelement=copy.deepcopy(extension)))
        
class RemoveExtension(Monitor):
    
    def __init__(self,env,path,extension):
        Monitor.__init__(self, env, path)
        
        header = ioelement.IOElement('Monitor',{'type':'RemoveExtension','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header,bodyelement=copy.deepcopy(extension)))
        
class AddAnchor(Monitor):
    
    def __init__(self,env,path):
        Monitor.__init__(self, env, path)
        
        header = ioelement.IOElement('Monitor',{'type':'AddAnchor','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header))
        
class RemoveAnchor(Monitor):
    
    def __init__(self,env,path):
        Monitor.__init__(self, env, path)
        
        header = ioelement.IOElement('Monitor',{'type':'RemoveAnchor','path':self.path})
        header.add(env.element)
        
        self.string = str(ioml.IOML(headelement=header))